package eSchool.GUI.Controls;

import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.table.TableModel;

public class JComboBoxExtended extends JComboBox {
    
    ArrayList list = new ArrayList();
    
    public void addItemsFrom(TableModel tableModel, int displayValueColumnIndex, int dataValueColumnIndex){
        for(int i=0; i < tableModel.getRowCount(); i++){
            super.addItem(tableModel.getValueAt(i, displayValueColumnIndex));
            list.add(tableModel.getValueAt(i, dataValueColumnIndex));
        }
    }

    public void addItem(Object displayValue, Object dataValue)
    {
        super.addItem(displayValue);
        list.add(dataValue);
    }
    
    public Object getSelectedValue()
    {
        
        return list.get(this.getSelectedIndex());
    }
    
    public Object getValueAt(int index)
    {
        return list.get(index);
    }
    
    public int getCount(){
        return list.size();
    }
    
    @Override
    public void removeAllItems(){
        super.removeAllItems();
        list.clear();
    }
    
    
}
